<%@ page language="java" contentType="text/javascript; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import='java.sql.*' %>
<%@page import="java.util.ArrayList"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>
<%@page import="net.sf.json.JSONArray"%>

<%String callback = request.getParameter("callback");%>
<%=callback %> (<%
	
	String nValue = request.getParameter("nValue");	
		
	Connection conn = null;
	PreparedStatement pstmt = null;
    
    JSONObject jo = new JSONObject();
    JSONArray ja = new JSONArray();
    
    
    try {
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost/itscreater", "itscreater", "campus123");
		
		String select = "select distinct City from PostLocation where Nation= ?;";
		pstmt = conn.prepareStatement(select);
		pstmt.setString(1, nValue);
		ResultSet rs = pstmt.executeQuery();
		
		while(rs.next()){
			String city = rs.getString("City");
			jo.put("CITY", city);
			ja.add(jo);	
			}
		out.print(ja);
    }
    
	finally {
        try { 
            pstmt.close();
        } 
        catch (Exception ignored) {
        }
        try { 
            conn.close();
        } 
        catch (Exception ignored) {
        }
    }
%>);